let params = {};

$("#loginBtn").on('click', function () {
    params.tel = $('#tel').val();
    params.pwd = $('#pwd').val();
    // console.log(params.tel)
    if (params.tel.trim().length == 0) {
        alert('请输入手机号')
        return;
    }
    if (params.pwd.trim().length == 0) {
        alert('请输入密码')
        return;
    }
    // console.log(params)
    // params.tel=tel;
    // params.pwd=pwd;
    $.ajax({
        type: "post",
        url: "http://localhost:3000/login",
        data: JSON.stringify(params),
        contentType: 'application/json',
        success: function (res) {
            // console.log(res.msg
            if (res.code === 200) {
                window.sessionStorage.setItem("token", res.token);
                window.location.href = "../public/index.html";
            } else {
                alert("账号或密码错误")
            }
        },
        error: function (res) {
            alert("服务端错误:res")
        }
    })
})

document.onkeydown = function (e) { // 回车提交表单
// 兼容FF和IE和Opera
    let theEvent = window.event || e;
    let code = theEvent.keyCode || theEvent.which || theEvent.charCode;
    if (code === 13) {
        let toclick = document.getElementById("loginBtn");
        toclick.click();
    }
}
